package com.jieshen.JDBC;

import com.jieshen.JDBC.utils.JDBCUtils;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * sql
 create table emp(
 id int,
 name varchar(20),
 email varchar(20)
 );
 */
public class DMLdemo {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    @Test
    public  void demo1() {
        String sql = "update emp set id=2 where id=0";
        int count = template.update(sql);
        System.out.println(count);
    }

    /**
     * 插入记录
     */
    @Test
    public void insert(){
        String sql = "insert into emp(id,name,email) values(?,?,?)";
        int count = template.update(sql,1,"UserA","test@xxx.com");
        System.out.println(count);
    }

    /**
     * 删除记录
     *
     */
    @Test
    public void delete(){
        String sql = "delete from emp where id = ?";
        int count = template.update(sql,1);
    }

}
